/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * articulos_sie_almacen_movi_estadis_detalle.java
 *
 * Created on 19/08/2011, 01:31:13 PM
 */

package sie_invdis;



import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
import java.text.ParseException;
import java.text.*;

/**
 *
 * @author Michelle
 */
public class articulos_sie_almacen_movi_estadis_detalle extends javax.swing.JFrame {
 private javax.swing.table.DefaultTableModel jtable_modelo_detallearticulos;

 
    bd_conexion x = new bd_conexion();
    ResultSet rs = null;
    /** Creates new form articulos_sie_almacen_movi_estadis_detalle */
    public articulos_sie_almacen_movi_estadis_detalle() {
        initComponents();
    }
public articulos_sie_almacen_movi_estadis_detalle(int opcion,String idmovimiento,String movimientodescribe,String idfiltro,String describefiltro) {
    this.iniciar_modelo_articulos();
        initComponents();
    this.carga_datos_detalle(opcion, idmovimiento, idfiltro);
    this.jtf_descripcionmovimiento.setText(idmovimiento+":"+movimientodescribe);
    this.jtf_detallereporte.setText(idfiltro+":"+describefiltro);

    }
    private void iniciar_modelo_articulos()
    {
        jtable_modelo_detallearticulos=new javax.swing.table.DefaultTableModel();//Creo el modelo
        jtable_modelo_detallearticulos.addColumn("<html><b>Tienda</b></html>");
        jtable_modelo_detallearticulos.addColumn("<html><b>Familia</b></html>");
        jtable_modelo_detallearticulos.addColumn("<html><b>Subfamilia</b></html>");
        jtable_modelo_detallearticulos.addColumn("<html><b>Id</b></html>");
        jtable_modelo_detallearticulos.addColumn("<html><b>Clave</b></html>");
        jtable_modelo_detallearticulos.addColumn("<html><b>Descripcion</b></html>");
        jtable_modelo_detallearticulos.addColumn("<html><b>Item</b></html>");
        jtable_modelo_detallearticulos.addColumn("<html><b>Cantidad</b></html>");
        jtable_modelo_detallearticulos.addColumn("<html><b>Costo</b></html>");
        jtable_modelo_detallearticulos.addColumn("<html><b>Precio</b></html>");
        jtable_modelo_detallearticulos.addColumn("<html><b>Foto</b></html>");
    }
private void carga_datos_detalle(int opcion,String idmovimiento,String busca)
 {
        this.LimpiarJTable();
        DecimalFormat miformat = new DecimalFormat("###,###,###,###");
        java.util.Date fechahoy=new Date();
        Object[] fnewRow = new Object[11];
        String idstat[]=null;
       //invoco al metodo que trae el recordset de datos
       rs = x.sieuno_executediversosv2("select * from x1sieuno_articulo_almacen_movextras_estadis_articulos("+opcion+",'"+busca+"',0,"+idmovimiento+") as (idmovidetalle integer,cnsdetmoext integer,cantidadproducto real,idalmpro integer,precio real,idtipven integer,preciocosto real,existencia double precision,idproducto integer,cntsdetpro integer,descripcion text,precioactual double precision,prerebaactual real,claveproducto text,familiaart integer,subfamilia integer,item character varying(80),tempoingreso smallint,nombrefamilia character varying(30),nombresubfamilia character varying(50),tempoentrada character varying(25),idstatus integer,idcattipmovext integer);",variables_global.getconexiongral());
        try
         {
            while (rs.next())
                {
                    idstat=rs.getString("claveproducto").toString().split(":");

                     fnewRow[0]=idstat[0]+":"+idstat[2];
                     fnewRow[1]=rs.getString("nombrefamilia");
                     fnewRow[2]=rs.getString("nombresubfamilia");
                     fnewRow[3]=rs.getString("idproducto");
                     fnewRow[4]=idstat[1];
                     fnewRow[5]=rs.getString("descripcion");
                     fnewRow[6]=rs.getString("item");
                     fnewRow[7]=miformat.format(rs.getFloat("cantidadproducto"));
                     fnewRow[8]=miformat.format(rs.getFloat("preciocosto"));
                     fnewRow[9]=miformat.format(rs.getFloat("precio"));
                     fnewRow[10]="";
                     jtable_modelo_detallearticulos.addRow(fnewRow);
                }
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
     
}

void LimpiarJTable()
    {
        while(jtable_modelo_detallearticulos.getRowCount()>0)jtable_modelo_detallearticulos.removeRow(0);
    }

private void dioclick(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
         System.out.println("dio doble  click");
         int fila = jt_detallearticulos.getSelectedRow();
         Object valor = jt_detallearticulos.getValueAt(fila, 3);

        //JFrame mainFrame = Sie_invdisApp.getApplication().getMainFrame();
        articulos_sie_editar fase=new articulos_sie_editar(valor.toString());
        fase.pack();
        fase.setVisible(true);
        //setVisible(false);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtf_descripcionmovimiento = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtf_detallereporte = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jt_detallearticulos = new javax.swing.JTable(){
            public boolean isCellEditable(int rowIndex, int mColIndex) {
                return false;
            }}
            ;
            jMenuBar1 = new javax.swing.JMenuBar();
            jMenu1 = new javax.swing.JMenu();
            jmni_salir = new javax.swing.JMenuItem();
            jMenu2 = new javax.swing.JMenu();
            jmni_escape = new javax.swing.JMenuItem();
            jMenu3 = new javax.swing.JMenu();

            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sie_invdis.Sie_invdisApp.class).getContext().getResourceMap(articulos_sie_almacen_movi_estadis_detalle.class);
            setTitle(resourceMap.getString("Form.title")); // NOI18N
            setName("Form"); // NOI18N

            jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel1.border.title"))); // NOI18N
            jPanel1.setName("jPanel1"); // NOI18N

            jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
            jLabel1.setName("jLabel1"); // NOI18N

            jtf_descripcionmovimiento.setEditable(false);
            jtf_descripcionmovimiento.setFont(resourceMap.getFont("jtf_descripcionmovimiento.font")); // NOI18N
            jtf_descripcionmovimiento.setText(resourceMap.getString("jtf_descripcionmovimiento.text")); // NOI18N
            jtf_descripcionmovimiento.setName("jtf_descripcionmovimiento"); // NOI18N

            jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
            jLabel2.setName("jLabel2"); // NOI18N

            jtf_detallereporte.setEditable(false);
            jtf_detallereporte.setFont(resourceMap.getFont("jtf_detallereporte.font")); // NOI18N
            jtf_detallereporte.setText(resourceMap.getString("jtf_detallereporte.text")); // NOI18N
            jtf_detallereporte.setName("jtf_detallereporte"); // NOI18N

            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jtf_descripcionmovimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jtf_detallereporte, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)))
                    .addContainerGap())
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jtf_descripcionmovimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jtf_detallereporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );

            jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel2.border.title"))); // NOI18N
            jPanel2.setName("jPanel2"); // NOI18N

            jScrollPane1.setName("jScrollPane1"); // NOI18N

            jt_detallearticulos.setModel(this.jtable_modelo_detallearticulos);
            jt_detallearticulos.setName("jt_detallearticulos"); // NOI18N
            jt_detallearticulos.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jt_detallearticulosMouseClicked(evt);
                    if(evt.getClickCount() >= 2)
                    {
                        dioclick(evt);
                        //System.out.println(" double click" );
                    }
                }
            });
            jScrollPane1.setViewportView(jt_detallearticulos);

            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1007, Short.MAX_VALUE)
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            );

            jMenuBar1.setName("jMenuBar1"); // NOI18N

            jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
            jMenu1.setName("jMenu1"); // NOI18N

            jmni_salir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK));
            jmni_salir.setIcon(resourceMap.getIcon("jmni_salir.icon")); // NOI18N
            jmni_salir.setText(resourceMap.getString("jmni_salir.text")); // NOI18N
            jmni_salir.setName("jmni_salir"); // NOI18N
            jmni_salir.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jmni_salirActionPerformed(evt);
                }
            });
            jMenu1.add(jmni_salir);

            jMenuBar1.add(jMenu1);

            jMenu2.setText(resourceMap.getString("jMenu2.text")); // NOI18N
            jMenu2.setName("jMenu2"); // NOI18N

            jmni_escape.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0));
            jmni_escape.setText(resourceMap.getString("jmni_escape.text")); // NOI18N
            jmni_escape.setName("jmni_escape"); // NOI18N
            jmni_escape.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jmni_escapeActionPerformed(evt);
                }
            });
            jMenu2.add(jmni_escape);

            jMenuBar1.add(jMenu2);

            jMenu3.setText(resourceMap.getString("jMenu3.text")); // NOI18N
            jMenu3.setName("jMenu3"); // NOI18N
            jMenuBar1.add(jMenu3);

            setJMenuBar(jMenuBar1);

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(411, Short.MAX_VALUE))
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(43, Short.MAX_VALUE))
            );

            pack();
        }// </editor-fold>//GEN-END:initComponents

    private void jmni_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_salirActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jmni_salirActionPerformed

    private void jmni_escapeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_escapeActionPerformed
        // TODO add your handling code here:
        this.jmni_salirActionPerformed(evt);
    }//GEN-LAST:event_jmni_escapeActionPerformed

    private void jt_detallearticulosMouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new articulos_sie_almacen_movi_estadis_detalle().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JMenuItem jmni_escape;
    private javax.swing.JMenuItem jmni_salir;
    private javax.swing.JTable jt_detallearticulos;
    private javax.swing.JTextField jtf_descripcionmovimiento;
    private javax.swing.JTextField jtf_detallereporte;
    // End of variables declaration//GEN-END:variables

}
